var app = new Vue({
  el: "#app",
  data: {
    linkList: LINK_LIST,
    navList: [
      {
        id: 1,
        title: "发布商机",
        link: LINK_LIST.PublishBusiness,
        target: "_blank", // 新窗口打开
      },
      {
        id: 2,
        title: "商机管理",
        link: LINK_LIST.BusinessManagement,
        target: "_self", // 当前窗口打开
      },
      {
        id: 3,
        title: "商铺管理",
        link: LINK_LIST.ShopManagement,
        target: "_self",
      },
      {
        id: 4,
        title: "增值服务",
        link: LINK_LIST.ValueImprovement,
        target: "_self",
      },
      {
        id: 8,
        title: "视频分发",
        link: LINK_LIST.VideoDistribute,
        target: "_self",
      },
      {
        id: 9,
        title: "回收地图",
        link: LINK_LIST.RecycleMap,
        target: "_blank",
      },
      {
        id: 10,
        title: "询价单",
        link: LINK_LIST.Inquiry,
        target: "_blank",
      },
      //{
      //  id: 5,
      //  title: "消息管理",
      //  link: LINK_LIST.MessageManagement,
      //  target: "_self",
      //},
      {
        id: 6,
        title: "积分管理",
        link: LINK_LIST.PointsManagement,
        target: "_self",
      },
      {
        id: 7,
        title: "廉政与建言",
        link: LINK_LIST.IntegritySuggestions,
        target: "_blank",
      },
    ],
    headerList: [
      {
        id: 1,
        title: "Feijiu",
        link: LINK_LIST.Home,
      },
      {
        id: 2,
        title: "我的商铺",
        link: LINK_LIST.Shop,
      },
      {
        id: 3,
        title: "帮助中心",
        link: LINK_LIST.Help,
      },
      {
        id: 4,
        title: "联系客服",
        link: LINK_LIST.Service,
      },
      {
        id: 5,
        title: "消息",
        link: LINK_LIST.Message,
      },
    ],
    businessManagement: [
      {
        id: 1,
        title: "发布的信息",
        link: LINK_LIST.BusinessPublish,
        list: [
          {
            id: 1,
            title: "已发信息",
            link: LINK_LIST.BusinessPublishPublished,
            num: 0,
          },
          {
            id: 2,
            title: "到期信息",
            link: LINK_LIST.BusinessPublishExpired,
            num: 0,
          },
          {
            id: 3,
            title: "待审商机",
            link: LINK_LIST.BusinessPublishReview,
            num: 0,
          },
        ],
      },
      {
        id: 2,
        title: "订阅的信息",
        link: LINK_LIST.BusinessSubscribe,
        list: [
          {
            id: 1,
            title: "资产信息",
            link: LINK_LIST.BusinessSubscribeAssets,
            num: 0,
          },
          {
            id: 2,
            title: "拍卖公告",
            link: LINK_LIST.BusinessSubscribeAuction,
            num: 0,
          },
          {
            id: 3,
            title: "行情报价",
            link: LINK_LIST.BusinessSubscribeQuotation,
            num: 0,
          },
        ],
      },
      {
        id: 3,
        title: "推荐生意",
        link: LINK_LIST.BusinessRecommend,
        list: [
          {
            id: 1,
            title: "独享生意",
            link: LINK_LIST.BusinessRecommendAlone,
            num: 0,
          },
          {
            id: 2,
            title: "资产信息",
            link: LINK_LIST.BusinessRecommendAssets,
            num: 0,
          },
          {
            id: 3,
            title: "拍卖公告",
            link: LINK_LIST.BusinessRecommendAuction,
            num: 0,
          },
        ],
      },
      {
        id: 4,
        title: "收藏的生意",
        link: LINK_LIST.BusinessCollection,
        list: [
          {
            id: 1,
            title: "资产信息",
            link: LINK_LIST.BusinessCollectionAssets,
            num: 0,
          },
          {
            id: 2,
            title: "拍卖公告",
            link: LINK_LIST.BusinessCollectionAuction,
            num: 0,
          },
          {
            id: 2,
            title: "供求信息",
            link: LINK_LIST.BusinessCollectionAuction,
            num: 0,
          },
        ],
      },
    ],
    tabActiveRecommend: 0,
    quotationTabs: ["废金属", "再生塑料", "废纸"],
    tabActiveQuotation: 0,
    notice: [],
    valueImprovement: {
      top: [],
      all: [],
      use: [],
    },
    myShop: {
      improveContent: [],
    },
    recommend: [],
    userInfo: {
      auth: [],
      inquiry: [],
    },
    speed: [],
    rank: [],
    quotation: [],
  },
  mounted() {
    this.getInfo();
  },
  methods: {
    // 获取信息
    getInfo() {
      this.getNotice();
      this.getBusinessManagement();
      this.getValueImprovement();
      this.getMyShop();
      this.getRecommend();
      this.getUserInfo();
      this.getSpeed();
      this.getRank();
    },
    // 获取公告
    getNotice() {
      apiGetNotice()
        .then((res) => {
          const { data } = res;
          if (data) {
            this.notice = data;
          }
        })
        .catch((err) => {
          this.$message.error((err && err.msg) || err);
        });
    },
    // 获取商机管理
    getBusinessManagement() {
      apiGetBusinessManagement()
        .then((res) => {
          const { data } = res;
          if (data) {
            this.businessManagement.forEach((item, index) => {
              if (!data[index]) return;
              item.list.forEach((subItem, subIndex) => {
                if (!data[index][subIndex]) return;
                subItem.num = data[index][subIndex];
              });
            });
          }
        })
        .catch((err) => {
          this.$message.error((err && err.msg) || err);
        });
    },
    // 获取增值提效
    getValueImprovement() {
      apiGetValueImprovement()
        .then((res) => {
          const { data } = res;
          if (data) {
            this.valueImprovement = data;
          }
        })
        .catch((err) => {
          this.$message.error((err && err.msg) || err);
        });
    },
    // 获取我的商铺
    getMyShop() {
      apiGetMyShop()
        .then((res) => {
          const { data } = res;
          if (data) {
            this.myShop = data;
          }
        })
        .catch((err) => {
          this.$message.error((err && err.msg) || err);
        });
    },
    // 获取推荐
    getRecommend() {
      apiGetRecommend({ type: this.tabActiveRecommend + 1 })
        .then((res) => {
          const { data } = res;
          if (data) {
            this.recommend = data;
          }
        })
        .catch((err) => {
          this.$message.error((err && err.msg) || err);
        });
    },
    // 获取用户信息
    getUserInfo() {
      apiGetUserInfo()
        .then((res) => {
          const { data } = res;
          if (data) {
            this.userInfo = data;
            if (this.userInfo.industry) {
              const index = this.quotationTabs.indexOf(this.userInfo.industry);
              if (index !== -1) {
                this.tabActiveQuotation = index;
              }
            }
            this.getQuotation();
          }
        })
        .catch((err) => {
          this.$message.error((err && err.msg) || err);
          this.getQuotation();
        });
    },
    // 获取成交速递
    getSpeed() {
      apiGetSpeed()
        .then((res) => {
          const { data } = res;
          if (data) {
            let list = [];
            data.forEach((item) => {
              if (list.length < 4) {
                list.push(item);
              } else {
                this.speed.push(list);
                list = [];
                list.push(item);
              }
            });
            if (list.length) {
              this.speed.push(list);
            }
          }
        })
        .catch((err) => {
          this.$message.error((err && err.msg) || err);
        });
    },
    // 获取行业排名
    getRank() {
      apiGetRank()
        .then((res) => {
          const { data } = res;
          if (data) {
            this.rank = data;
          }
        })
        .catch((err) => {
          this.$message.error((err && err.msg) || err);
        });
    },
    // 获取报价
    getQuotation() {
      apiGetQuotation({ type: this.tabActiveQuotation + 1 })
        .then((res) => {
          const { data } = res;
          if (data) {
            this.quotation = data;
          }
        })
        .catch((err) => {
          this.$message.error((err && err.msg) || err);
        });
    },
    // 切换tab
    onTabChangeRecommend(index) {
      this.tabActiveRecommend = index;
      this.getRecommend();
    },
    // 切换tab
    onTabChangeQuotation(index) {
      this.tabActiveQuotation = index;
      this.getQuotation();
    },
  },
});
